package logic

import (
	"context"
	"zhihu/zhihurpc/models/mysql"
	"zhihu/zhihurpc/zhihurpcclient"

	"zhihu/zhihurpc/internal/svc"
	"zhihu/zhihurpc/zhihurpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProblemListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewProblemListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProblemListLogic {
	return &ProblemListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ProblemListLogic) ProblemList(in *zhihurpc.ProblemListRequest) (*zhihurpc.ProblemListResponse, error) {
	// todo: add your logic here and delete this line
	var problemlist []mysql.Problem
	mysql.DB.Debug().Find(&problemlist)
	var problems []*zhihurpcclient.ProblemList
	for _, list := range problemlist {
		problem := zhihurpcclient.ProblemList{
			Id:      int64(list.ID),
			Content: list.Content,
			UserId:  list.UserId,
			Hot:     list.Hot,
		}
		problems = append(problems, &problem)
	}
	return &zhihurpc.ProblemListResponse{
		List: problems,
	}, nil
}
